package com.example.springskywalking;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.Collections;
import java.util.Map;

@SpringBootApplication
public class SpringSkywalkingApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringSkywalkingApplication.class, args);
    }


    @Bean
    public RestTemplate rt() {
        RestTemplate restTemplate = new RestTemplate();
        restTemplate.setRequestFactory(new SimpleClientHttpRequestFactory());
        return restTemplate;
    }


    @RestController
    @RequestMapping("/rpc")
    public static class DemoRpcController {
        @Autowired
        private RestTemplate template;

        @GetMapping("/demo")
        public Map demo() {
            return Collections.singletonMap("k1", "v1");
        }

        @GetMapping("/go")
        public Map invoke() {
            return template.getForObject("http://localhost:8081/trace", Map.class);
        }
    }
}
